package com.earthquake.monitor_system.service.impl;

import com.earthquake.monitor_system.controller.resultType.Pagination;
import com.earthquake.monitor_system.dao.SeismicInformationDao;
import com.earthquake.monitor_system.domain.SeismicInformation;
import com.earthquake.monitor_system.service.ITF.ISeismicInformation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SeismicInformationImpl implements ISeismicInformation {
    @Autowired
    private SeismicInformationDao seismicInformationDao;
    @Override
    public Boolean insert(SeismicInformation seismicInformationList) throws Exception {
       return seismicInformationDao.insert(seismicInformationList);
    }

    @Override
    public SeismicInformation queryTimestampEq(String timestamp) {
        SeismicInformation seismicInformation = seismicInformationDao.queryTimestampEq(timestamp);
        return seismicInformation;
    }

    @Override
    public Object querySeismicInfoList(Pagination pagination) {
        Map<String,Integer> list = new HashMap<>();
        int pageSize = pagination.getPageSize();
        int currentPage = pagination.getCurrentPage();
        list.put("startIndex",(currentPage-1)*pageSize);
        list.put("currentPage",currentPage);
        list.put("pageSize",pageSize);
        String seismicInfoCount = seismicInformationDao.getSeismicInfoCount();
        list.put("total", Integer.valueOf(seismicInfoCount));
        List<SeismicInformation> SeismicInformationList = seismicInformationDao.querySeismicInfoList(list);
        Map<String,Object> list2 = new HashMap<>();
        list2.put("SeismicInformationList",SeismicInformationList);
        list2.put("pagination", list);
        return list2;
    }

    @Override
    public List<SeismicInformation> getCoordinatePoint(String stamp) {
        List<SeismicInformation> coordinatePoint = seismicInformationDao.getCoordinatePoint(stamp);
        return coordinatePoint;
    }



    @Override
    public List getEarthquakeMagnitudek() {
        List<String> list= new ArrayList<>();
        String earthquakeMagnitudek = seismicInformationDao.getEarthquakeMagnitudek(0, 3);
        String earthquakeMagnitudek1 = seismicInformationDao.getEarthquakeMagnitudek(3, 5);
        String earthquakeMagnitudek2 = seismicInformationDao.getEarthquakeMagnitudek(5, 7);
        String earthquakeMagnitudek3 = seismicInformationDao.getEarthquakeMagnitudek(7, 15);
        list.add(earthquakeMagnitudek);
        list.add(earthquakeMagnitudek1);
        list.add(earthquakeMagnitudek2);
        list.add(earthquakeMagnitudek3);
        return list;
    }
    @Override
    public String getEarthquakeMagnitudek(Integer Start, Integer End) {
        return null;
    }
    @Override
    public Boolean deleteById(String id) {
        Boolean s = seismicInformationDao.deleteById(id);
        return s;
    }
}
